package com.block.common.encrypt.service.type;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.block.common.encrypt.service.IEncryptTypeServcie;
import com.block.common.model.dto.EncryptKeyDTO;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

@Service
public class AesEncrpytService implements IEncryptTypeServcie {

    @Override
    public JSONObject decryptTranData(EncryptKeyDTO keyInfoDTO, JSONObject paramObject) {
        String content = paramObject.getString("tranData");
        String deContent = SecureUtil.aes(keyInfoDTO.getAppSecret().getBytes(StandardCharsets.UTF_8)).decryptStr(content);
        return JSON.parseObject(deContent);
    }

    /**
     * {"tranData":"w+glyZVFW5eAufA7DDMrGnFswaXecHlhKis2CCWqLLRW1fRU4I1EOSmMXFtEBVH/uyd8TGawG2B/mWgLiwwggk2VJkJxBoi6taw97Yny/j6sVTD5Au00Rp+OTXIw/7vPxlKNKn3rbt6TtYwDrPXMJ957m3H6/1MDP5q39m/Drrc=","appCode":"RA3RPE","requestNo":"d140e472-f036-4888-b83c-d8beb38a1666"}
     * @param args
     */

    public static void main(String[] args) {

        String tranData = "w+glyZVFW5eAufA7DDMrGnFswaXecHlhKis2CCWqLLRW1fRU4I1EOSmMXFtEBVH/uyd8TGawG2B/mWgLiwwggk2VJkJxBoi6taw97Yny/j6sVTD5Au00Rp+OTXIw/7vPxlKNKn3rbt6TtYwDrPXMJ957m3H6/1MDP5q39m/Drrc=";

        String aesKey = "KKXJHT9H5HJP28RYUJN1Z6W20KL0Y8UE";

        String s = SecureUtil.aes(aesKey.getBytes(StandardCharsets.UTF_8)).decryptStr(tranData);

        System.out.println(s);

    }
}
